# -*- coding: utf-8 -*-
'''
配置模块
@author: lowzoom
'''
from boot import rna_handler
import main
import os
import pickle

# 用户偏好设置
pref = {}

# 配置文件的路径
CONFIG_PATH = os.path.join(main.base_path, 'data', 'cfg')

# 设置的键值
GAME_PATH = 'game.path' # 游戏安装路径
RNA_PATH = 'game.rna.path' # 游戏配置文件路径
MOVIE_PATH = 'game.mov.path' # 开头动画文件夹路径
WINDOW_STATE = 'window.state' # 窗口状态

def load():
	'''
	读取配置文件
	'''
	if os.path.isfile(CONFIG_PATH):
		with open(CONFIG_PATH, 'r') as cfg_file:
			pref.update(pickle.load(cfg_file))
	else:
		# 配置文件不存在时创建默认配置
		pref[GAME_PATH] = None
		save()

def save():
	'''
	保存配置到文件
	'''
	with open(CONFIG_PATH, 'w') as cfg_file:
		pickle.dump(pref, cfg_file)

def set_game_path(game_path):
	pref[GAME_PATH] = game_path
	pref[RNA_PATH] = os.path.join(game_path, rna_handler.RNA_FILENAME)
	pref[MOVIE_PATH] = os.path.join(game_path, 'data', 'movies')
